package com.gymjournal

import org.junit.Test

import java.util.concurrent.TimeUnit

import static junit.framework.Assert.assertFalse
import static junit.framework.Assert.assertNotNull
import static junit.framework.Assert.assertTrue

/**
 * See the API for {@link grails.test.mixin.domain.DomainClassUnitTestMixin} for usage instructions
 */
class TrainingTests {

    @Test
    void testSave() {
        def now = new Date()
        def start = now - 1
        def finish = new Date(start.time + TimeUnit.HOURS.toMillis(2))
        def training = new Training()

        assertTrue training.validate()

        training.dateCreated = now
        assertTrue training.validate()

        training.dateCreated = null
        training.startDate = start
        assertFalse training.validate()

        training.note = new Note(content: 'first training')
        assertFalse training.validate()

        training.finishDate = finish
        assertTrue training.validate()

        assertNotNull training.save()
        assertNotNull training.id
    }
}
